package com.firewolf.springcloud.controller;

import com.firewolf.springcloud.pojo.User;
import com.firewolf.springcloud.service.UserService;
import com.firewolf.springcloud.vo.ResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 作者：刘兴
 * 时间:19/2/14
 **/
@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    private UserService userService;

    @GetMapping("/list")
    public List<User> userList(){
        List<User> userList = userService.findUsers();
        return  userList;
    }


    /**
     * Post传递对象
     * @param user
     * @return
     */
    @PostMapping
    public ResponseVO add1(User user){
        return  userService.add1(user);
    }

    @PostMapping("/a")
    public ResponseVO add2(@RequestParam("id") Integer uid, @RequestParam("uname") String name){
       return  userService.add2(uid,name);
    }


    @GetMapping("/b")
    public List<User> get(){
        return userService.get();
    }

    @GetMapping("/c")
    public List<User> get(User u){
        return userService.get(u);
    }

    @GetMapping("/d")
    public List<User> get(@RequestParam("id") Integer uid, @RequestParam("uname") String name){
        return userService.get(uid,name);
    }

    //占位符传参
    @DeleteMapping("/e/{id}/xxx/{name}")
    public ResponseVO delete(@PathVariable("id") Integer uid,@PathVariable("name") String uname){
        return userService.delete(uid,uname);

    }


}
